#include "stdafx.h"
#include "GameInstance.h"
#include "CGameStateCreate.h"
#include "CGameStateMove.h"
#include "CGameStateEquip.h"
#include "CGameStateBattle.h"

GameInstance::GameInstance()
{
	IGameState* pgs = new CGameStateCreate(this);
	m_gameStates[EGS_CREATE_ACTOR] = pgs;
	pgs = new CGameStateMove(this);
	m_gameStates[EGS_ACTOR_MOVE] = pgs;
	pgs = new CGameStateEquip(this);
	m_gameStates[EGS_ACTOR_EQUIP] = pgs;
	pgs = new CGameStateBattle(this);
	m_gameStates[EGS_ACTOR_BATTLE] = pgs;
	m_gameStates[EGS_GAME_OVER] = 0;
}
GameInstance::~GameInstance()
{
	for(int i = 0; i < EGS_COUNT; i++)
	{
		if(m_gameStates[i])
			delete m_gameStates[i];
		m_gameStates[i] = 0;
	}
}

void GameInstance::Run()
{
	E_GAME_STATE gameState = EGS_CREATE_ACTOR;
	while(gameState != EGS_GAME_OVER)
	{
		if(m_gameStates[gameState])
		{
			m_gameStates[gameState]->Enter();
			m_gameStates[gameState]->Update();
			gameState = m_gameStates[gameState]->Exit();
		}
		else
		{
			gameState = EGS_GAME_OVER;
		}
	}
}